/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.perlak.camel.search;

import com.perlak.camel.BaseRouteBuilder;
import com.perlak.camel.DebugLogProcessor;
import com.perlak.camel.Queues;
import com.perlak.filesearch.FileSearchRequest;
import com.perlak.messages.FileSearch.fileSearchJob;
import com.perlak.messages.FileSearch.fileSearchRequest;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author mateusz
 */
public final class SearchRouteBuilder extends BaseRouteBuilder {

  /**
   * Configures routes for search operations
   * @throws Exception 
   */
  @Override
  public void configure() throws Exception {
    from(getQueue(Queues.Search.REQUEST)).
            process(new DebugLogProcessor("Processing search request.")).
            process(new SearchProcessor(SearchProcessor.SEARCH_REQUEST)).
            to(getQueue(Queues.Search.RESPONSE));


    //test
    from("file:///ap/fw/input").
            process(new Processor() {

      @Override
      public void process(Exchange exchng) throws Exception {
        fileSearchJob.Builder b = fileSearchJob.newBuilder();
        b.setName("TEST");
        fileSearchRequest.Builder rb = fileSearchRequest.newBuilder();
        rb.setSource("LOCAL");
        rb.setSearchName("XML");
        rb.setFullDirPath("/ap/fs/search");
        b.addRequest(rb);

        exchng.getOut().setBody(b.build().toByteString());
      }
    }).to("file:///ap/fw/output");
  }

  /**
   * Gets logger for this class.
   * @return logger
   */
  @Override
  public Logger getLog() {
    return LoggerFactory.getLogger(SearchRouteBuilder.class);
  }
}
